﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Power.Common;
using Power.Models;
using Power.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace Power.ViewModel
{
    public class RegisterViewModel: ViewModelBase
    {
        private Register model;
        public RegisterViewModel(Register model)
        {
            this.model = model;
            WindowCloseCommand = new RelayCommand(OnWindowCloseClick);
            WindowMinCommand = new RelayCommand(OnWindowMinClick);
            NextOne = new RelayCommand(OnNextOne);
            NextTwo = new RelayCommand(OnNextTwo);
            Data = new RegisterEntity
            {
                //初始化数据
                ProList = Common.Common.GetProSelectList(),
                RoleList = Common.Common.GetRoleSelectList()
            };
        }

        /// <summary>
        /// 最小化
        /// </summary>
        private void OnWindowMinClick()
        {
            model.WindowState = WindowState.Minimized;
        }

        /// <summary>
        /// 关闭
        /// </summary>
        private void OnWindowCloseClick()
        {
            Login window = new Login();
            window.WindowStartupLocation = WindowStartupLocation.Manual;
            window.Left = this.model.Left;  //使新窗口位置在原来的位置上
            window.Top = this.model.Top;  //使新窗口位置在原来的位置上
            window.Show();  //打开新窗口
            this.model.Close();   //关闭当前窗口
        }

        /// <summary>
        /// 跳转到第二个页面
        /// </summary>
        private void OnNextOne()
        {
            var userName =  this.model.UserName.Text;
            var pd1 = this.model.pb1.Password;
            var pd2 = this.model.pb2.Password;
            var phone = this.model.Phone.Text;

            model.reg1.Visibility = Visibility.Collapsed;
            model.til1.Visibility = Visibility.Collapsed;

            model.reg2.Visibility = Visibility.Visible;
            model.til2.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// 跳转到第三个页面
        /// </summary>
        private void OnNextTwo()
        {
            var userName = this.model.UserName.Text;
            var pd1 = this.model.pb1.Password;
            var pd2 = this.model.pb2.Password;
            var phone = this.model.Phone.Text;

            //////获取选中的项目列表  角色列表
            var pro = this.model.ProList.SelectedItem;
            var role = this.model.RoleList.SelectedItem;

            model.reg2.Visibility = Visibility.Collapsed;
            model.til2.Visibility = Visibility.Collapsed;
            model.reg3.Visibility = Visibility.Visible;
            model.til3.Visibility = Visibility.Visible;
        }

        #region 
        public RelayCommand<WindowState> WindowMaxCommand { get; private set; }
        public RelayCommand WindowCloseCommand { get; private set; }
        public RelayCommand WindowMinCommand { get; private set; }

        public RelayCommand NextOne { get; private set; }

        public RelayCommand NextTwo { get; private set; }

        public RegisterEntity Data { get; private set; }
        #endregion
    }

}
